using System.Collections.Generic;
using DG.Tweening;
using UnityEngine;

public class CityBuildingVisualHandler : MonoBehaviour
{
	public List<GameObject> Levels = new List<GameObject>();

	public Transform Anim;

	private Tween _currentTween;

	private void Awake()
	{
		if (Levels != null && Levels.Count != 0)
		{
			return;
		}
		Levels = new List<GameObject>();
		if (!(Anim != null))
		{
			return;
		}
		foreach (Transform item in Anim)
		{
			Levels.Add(item.gameObject);
		}
	}

	private void OnDestroy()
	{
	}

	public void OnRvx2(bool enable)
	{
		if (_currentTween != null && _currentTween.IsActive())
		{
			_currentTween.Kill();
		}
		Anim.transform.localScale = Vector3.one;
		_currentTween = Anim.DOScale(Vector3.one * 1.1f, 0.4f).SetEase(Ease.OutQuad).SetLoops(-1, LoopType.Yoyo);
	}

	public void SetLevel(int level)
	{
		for (int i = 0; i < Levels.Count; i++)
		{
			Levels[i].SetActive(i == level);
		}
		if (level >= Levels.Count && Levels.Count > 0)
		{
			Levels[Levels.Count - 1].SetActive(value: true);
		}
	}

	[ExposeMethodInEditor(false, false)]
	public void Upgrade()
	{
		for (int i = 0; i < Levels.Count - 1; i++)
		{
			if (Levels[i].activeSelf)
			{
				Levels[i].SetActive(value: false);
				Levels[i + 1].SetActive(value: true);
				break;
			}
		}
		DoUpgradeAnim();
	}

	public void DoUpgradeAnim()
	{
		if (_currentTween != null && _currentTween.IsActive())
		{
			_currentTween.Kill();
		}
		if (!(Anim != null))
		{
			return;
		}
		Anim.localScale = Vector3.zero;
		Anim.DOScale(Vector3.one, 0.4f).SetEase(Ease.OutBack).OnComplete(delegate
		{
			if (CityBuildingManager.Instance.IsX2Enable())
			{
				OnRvx2(enable: true);
			}
		});
	}

	[ExposeMethodInEditor(false, false)]
	public void ResetLevel0()
	{
		SetLevel(0);
	}

	private void Reset()
	{
		Anim = base.transform.Find("Anim");
		Levels = new List<GameObject>();
		if (!(Anim != null))
		{
			return;
		}
		foreach (Transform item in Anim.transform)
		{
			Levels.Add(item.gameObject);
		}
	}
}
